package com.liang.auth.domain.service.impl;

import com.liang.auth.domain.bo.AuthRolePermissionBO;
import com.liang.auth.domain.convert.AuthRolePermissionBOConverter;
import com.liang.auth.domain.service.AuthRolePermissionDomainService;
import com.liang.auth.infra.basic.entity.AuthRolePermission;
import com.liang.auth.infra.basic.service.AuthRolePermissionService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
@RequiredArgsConstructor
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {

    private final AuthRolePermissionService authRolePermissionService;

    @Override
    public void save(AuthRolePermissionBO authRolePermissionBO) {
        Long roleId = authRolePermissionBO.getRoleId();
        List<AuthRolePermission> authRolePermissions = authRolePermissionBO.getPermissionIdList().stream()
                .map(permissionId -> {
                    AuthRolePermission authRolePermission = new AuthRolePermission();
                    authRolePermission.setRoleId(roleId);
                    authRolePermission.setPermissionId(permissionId);
                    return authRolePermission;
                })
                .collect(Collectors.toList());
        authRolePermissionService.saveBatch(authRolePermissions);
    }
}
